﻿using AutoMapper;
using B.S.Material.Domain.Scraps;
using B.S.Material.ErrorCode;
using B.S.Material.Read.Api.Applications.Command.ScrapBreakdownCommand;
using MediatR;
using SqlSugar;

namespace B.S.Material.Read.Api.Applications.Handler.ScrapBreakdownHandler
{
    public class GetScrapBreakdownHandler : IRequestHandler<GetScrapBreakdownCommand, ApiResult<List<ScrapBreakdown>>>
    {
        private readonly ISqlSugarClient db;
        private readonly IMapper mapper;
        public GetScrapBreakdownHandler(ISqlSugarClient db, IMapper mapper)
        {
            this.db = db;
            this.mapper = mapper;
        }

        public async Task<ApiResult<List<ScrapBreakdown>>> Handle(GetScrapBreakdownCommand request, CancellationToken cancellationToken)
        {
            ApiResult<List<ScrapBreakdown>> result = new ApiResult<List<ScrapBreakdown>>();

            var item = await db.Queryable<ScrapBreakdown>().Where(x => x.IsDel == false).ToListAsync();

            result.Code = ApiEnum.显示成功;
            result.MAG = ApiEnum.显示成功.ToString();
            result.data = item;

            return result;
        }
    }
}
